<?php

namespace App\Http\Requests\customer;

use App\Http\ValidateResult;
use Illuminate\Support\Facades\Validator;

trait ResourceRequest
{
    public static function add_check(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'api_type' => 'required|integer|in:1,2',
            'resource_type' => 'required|integer|in:1,2,3,4',
            'name' => 'required',
            'code' => 'required',
            'business' => 'required',
        ], [
            'api_type.required' => '请选择api类型',
            'resource_type.required' => '请选择资源类型',
            'name.required' => '请填写资源名称',
            'code.required' => '请填写资源代码',
            'business.required' => '请填写商家名称',
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }

}
